<!DOCTYPE html> 
<html lang="en"> 
<head> 
    
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title></title> 
   
    <style type="text/css">
        @import url("/pages/import/base.css");
        html, body{ margin:0; height:100%; }
    </style>
    <script type="text/javascript" src="/pages/import/base.js"></script>
    
</head> 
<body class="easyui-layout" style="overflow: hidden;">
    <div id='jsstrengthen'></div>
  <script type="text/javascript"> 
  </script>
    <div data-options="region:'center',iconCls:'icon-reload',title:'',split:true" style="width:70%;height: 100%">
        <table id="dg" class='easyui-datagrid' style="width:100%;height:100%" title="" data-options="
                  rownumbers:true,
                  singleSelect:true,
                  autoRowHeight:false,
                  pagination:true,
                  fitColumns:false,
                  striped:true,
                  checkOnSelect:true,
                  selectOnCheck:true,
                  collapsible:true,
                  toolbar:'#tb',
                  pageSize:20">
            <thead>
                <tr href="#">                      
              </tr>
            </thead>
          </table>    
          <div id="tb" style="height:35px">
                <form id="queryForm" class="search-box">
                <a id='btnQuery' href="javascript:void(0)" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-search" onclick="functionQuery()" style="margin-left: 0px">搜索</a>          
                <a id='btnClear' href="javascript:void(0)" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-refresh" onclick="functionClear()" style="margin-left: 0px">清除</a>                     
                </form>                        
          </div>
       </div>
    </div>
</body>

<script type="text/javascript">
var key = '';
var formUrl = '';
var tableName = '';
$(function() {
    loadDatagraid();
});

</script>
<script type="text/javascript">


    function loadDatagraid() {
        $.ajax({
            url: '/develop/pagetemplate/getDatagraidAndColumns.do',
            data: {
                'uuid': shuoheUtil.getUrlHeader().uuid
            },
            error:function(error)
            {
              console.info(error);
            },
            success: function(data) {   
              try{
                  addDatagraidButton(data.datagraidButtons);
                  addSearchBox(data.searchForm);
                  initDatagraid(data);
                  Easyui.Js.loadJsCode(data.datagraid.jsstrengthen);

              }
              catch(error)
              {
                  console.info(error);
              }
            }
        });    
    }

    function addDatagraidButton(datagraidButtons)
    {
        for(var i=0;i<datagraidButtons.length;i++)
        {
            var html = Easyui.Button.createButtonHtml(
                datagraidButtons[i].id_name,
                datagraidButtons[i].iconCls,
                datagraidButtons[i].plain,
                datagraidButtons[i].onclick,
                datagraidButtons[i].value
            );
            $('#tb').append(html);

            $('#'+datagraidButtons[i].id_name).linkbutton({    
                iconCls: datagraidButtons[i].iconCls
            });  
        }
    }
    function addSearchBox(searchForm)
    {

        for(var i=0;i<searchForm.length;i++)
        {
            if(searchForm[i].clazz == 'easyui-datetimebox')
            {
                var html = Easyui.DatetimeBox.createHtml(
                    searchForm[i].id
                );
                $('#queryForm').prepend(html);
                $('#'+searchForm[i].id).datetimebox({
                    required:false
                });  
            }
            // else if(searchForm[i].clazz == 'easyui-datebox')
            // {
            //     var html = Easyui.DateBox.createHtml(
            //         searchForm[i].id
            //     );
            //     $('#queryForm').prepend(html);
            //     $('#'+searchForm[i].id).datebox({
            //         required:false
            //     });  
            // }
            else if(searchForm[i].clazz == 'easyui-textbox')
            {
                var html = Easyui.TextBox.createHtml(
                    searchForm[i].id,
                    searchForm[i].prompt
                );
                $('#queryForm').prepend(html);
                $('#'+searchForm[i].id).textbox();  
            }
            else if(searchForm[i].clazz == 'easyui-combotree')
            {
                var html = Easyui.ComboTree.createHtml(
                    searchForm[i].id,
                    searchForm[i].value,
                    '',//url,
                    searchForm[i].iconCls,
                    searchForm[i].prompt,
                    searchForm[i].hidden
                );
                $('#queryForm').prepend(html);

                $('#'+searchForm[i].id).combotree({    
                    text:searchForm[i].text
                });  
            }
        }
    }
    function initDatagraid(data)
    {
        $('#dg').datagrid({
            url: data.datagraid.url,
            method: 'get',
            autoRowHeight:data.datagraid.rownumbers,
            checkOnSelect:data.datagraid.checkOnSelect,
            collapsible:data.datagraid.collapsible,
            fitColumns:data.datagraid.fitColumns,
            pagination:data.datagraid.pagination,
            rowNumbers:data.datagraid.rowNumbers,
            selectOnCheck:data.datagraid.selectOnCheck,
            singleSelect:data.datagraid.singleSelect,
            striped:data.datagraid.striped,
            columns: data.datagraidColumns,            
            queryParams: {
            },
            onLoadSuccess: function(data) {                
            }
        });
    }

</script>
<script type="text/javascript">
    //新增成功
    function addDialogCallBackSuccess1(index) {
        layer.close(index)
        messageSaveOK()
        $('#dg').datagrid('reload')
    }

    function addDialogCallBackSuccess(uuid, params, index) {
        var str = uuid + "," + formUrl + "," + tableName;
        console.info("=str=" + str);
        $.ajax({
            url: "/flow/startProcessWithForm",
            type: "POST",
            dataType: 'json',
            data: {
                modelName: key,
                uuid: uuid,
                completeNow: true
            },
            success: function(result) //成功
            {
                layer.msg(result.msg);
                location.reload();
                var pid = result.obj.rootId;
                layer.open({
                    type: 2,
                    title: "指定表单别名",
                    shadeClose: false,
                    shade: 0.3,
                    maxmin: true, //开启最大化最小化按钮
                    area: ["380px", "200px"],
                    btn: ["保存"],
                    content: "/tips/toAddTips",
                    yes: function(index) {
                        var res = window["layui-layer-iframe" + index].callbackdata();
                        $.ajax({
                            url: "/tips/addTips",
                            type: "POST",
                            dataType: 'json',
                            data: {
                                tName: res,
                                procInsId: pid,
                            },
                            success: function(result) //成功
                            {
                                layer.msg(result.msg);
                            }
                        });
                        layer.close(index);
                        location.reload();
                    }
                });
            }
        });
    }
</script>
<script type="text/javascript">
    //修改成功
    function editDialogCallBackSuccess1(index) {
        layer.close(index)
        messageSaveOK()
        $('#dg').datagrid('reload')
    }

    function editDialogCallBackSuccess(uuid) {
        var str = uuid + "," + formUrl + "," + tableName;
        console.info("=str=" + str);
        $.ajax({
            url: "/flow/startProcessWithForm",
            type: "POST",
            dataType: 'json',
            data: {
                modelName: key,
                uuid: uuid,
                completeNow: true
            },
            success: function(result) //成功
            {
                layer.msg(result.msg);
                location.reload();
                var pid = result.obj.rootId;
                layer.open({
                    type: 2,
                    title: "指定表单别名",
                    shadeClose: false,
                    shade: 0.3,
                    maxmin: true, //开启最大化最小化按钮
                    area: ["380px", "200px"],
                    btn: ["保存"],
                    content: "/tips/toAddTips ",
                    yes: function(index) {
                        var res = window["layui-layer-iframe" + index].callbackdata();
                        $.ajax({
                            url: "/tips/addTips",
                            type: "POST",
                            dataType: 'json',
                            data: {
                                tName: res,
                                procInsId: pid,
                            },
                            success: function(result) //成功
                            {
                                layer.msg(result.msg);
                            }
                        });
                        layer.close(index);
                        location.reload();
                    }
                });
            }
        });
    }
    //查看一条数据
</script>
<script type="text/javascript">
    //查看一条数据
    function functionView() {
        var row = $('#dg').datagrid('getSelected')
        if (row == null) {
            alert('请先选择一条数据')
            return false
        }
        layer.open({
            type: 2,
            title: '查看数据',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['900px', document.body.clientHeight - 20 + 'px'],
            btn: '关闭',
            content: '/pages/formDevelopment/seeFormOrder.jsp?title=' + tableName + '&uuid=' + row.uuid,
            yes: function(index) {
                layer.close(index)
            }
        })
    }
    //删除一条数据
    function functionDelete() {
        var row = $('#dg').datagrid('getSelected')
        if (row == null) {
            alert('请先选择一条数据')
            return false
        } else {
            var flag = true
            if (isAct == '0') {
                $.ajax({
                    url: "/flow/getStats",
                    type: "POST",
                    dataType: 'json',
                    async: false,
                    data: {
                        'uuid': row.uuid
                    },
                    success: function(result) //成功
                    {
                        if (result.msg != '未开启' && result.msg != '项目经理') {
                            flag = false
                        }
                    }
                })
            }
            if (flag) {
                $.messager.confirm('确认', '您确认想要删除吗？', function(r) {
                    if (r) {
                        $.ajax({
                            url: "/crm/ActionFormUtil/delete.do",
                            type: "POST",
                            dataType: 'text',
                            data: {
                                'tableName': formName,
                                'id': row.id
                            },
                            error: function() //失败
                            {
                                messageDeleteError()
                            },
                            success: function(data) //成功
                            {
                                data = $.trim(data)
                                if (data == '0') {
                                    messageDeleteError()
                                } else {
                                    messageDeleteOK()
                                    $('#dg').datagrid('reload')
                                }
                            }
                        })
                    }
                })
            } else {
                $.messager.alert('提醒', '流程已开启，不能删除数据。', 'warning')
            }
        }
    }
</script>
